package com.sjy.project.fym.signin.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sjy.framework.aspectj.lang.annotation.Log;
import com.sjy.framework.aspectj.lang.enums.BusinessType;
import com.sjy.project.fym.signin.domain.FyUserSignin;
import com.sjy.project.fym.signin.service.IFyUserSigninService;
import com.sjy.framework.web.controller.BaseController;
import com.sjy.framework.web.domain.AjaxResult;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.framework.web.page.TableDataInfo;

/**
 * 人员签到打卡记录Controller
 * 
 * @author sjy
 * @date 2022-04-18
 */
@Controller
@RequestMapping("/fym/signin")
public class FyUserSigninController extends BaseController
{
    private String prefix = "fym/signin";

    @Autowired
    private IFyUserSigninService fyUserSigninService;

    @RequiresPermissions("fym:signin:view")
    @GetMapping()
    public String signin()
    {
        return prefix + "/signin";
    }

    /**
     * 查询人员签到打卡记录列表
     */
    @RequiresPermissions("fym:signin:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FyUserSignin fyUserSignin)
    {
        startPage();
        List<FyUserSignin> list = fyUserSigninService.selectFyUserSigninList(fyUserSignin);
        return getDataTable(list);
    }

    /**
     * 导出人员签到打卡记录列表
     */
    @RequiresPermissions("fym:signin:export")
    @Log(title = "人员签到打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FyUserSignin fyUserSignin)
    {
        List<FyUserSignin> list = fyUserSigninService.selectFyUserSigninList(fyUserSignin);
        ExcelUtil<FyUserSignin> util = new ExcelUtil<FyUserSignin>(FyUserSignin.class);
        return util.exportExcel(list, "人员签到打卡记录数据");
    }

    /**
     * 新增人员签到打卡记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存人员签到打卡记录
     */
    @RequiresPermissions("fym:signin:add")
    @Log(title = "人员签到打卡记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FyUserSignin fyUserSignin)
    {
        return toAjax(fyUserSigninService.insertFyUserSignin(fyUserSignin));
    }

    /**
     * 修改人员签到打卡记录
     */
    @RequiresPermissions("fym:signin:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FyUserSignin fyUserSignin = fyUserSigninService.selectFyUserSigninById(id);
        mmap.put("fyUserSignin", fyUserSignin);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员签到打卡记录
     */
    @RequiresPermissions("fym:signin:edit")
    @Log(title = "人员签到打卡记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FyUserSignin fyUserSignin)
    {
        return toAjax(fyUserSigninService.updateFyUserSignin(fyUserSignin));
    }

    /**
     * 删除人员签到打卡记录
     */
    @RequiresPermissions("fym:signin:remove")
    @Log(title = "人员签到打卡记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fyUserSigninService.deleteFyUserSigninByIds(ids));
    }
}
